package com.jali.crud.controller;

import com.jali.crud.bean.JaTaskItem;
import com.jali.crud.service.JaTaskItemService;
import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.MultimediaInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.File;

/**
 * @author jali
 * @create 2019-01-23 19:29
 */
@Controller
public class MakeDataController {

    @Autowired
    JaTaskItemService jaTaskItemService;

    @RequestMapping("/makeJaTaskItems")
    public void makeJaTaskItems() throws EncoderException {
        File file = new File("G:\\Java视频\\Linux\\视频");
        int count = 0;
        System.out.println("www");
        for (File subFile : file.listFiles()){
            JaTaskItem jaTaskItem = new JaTaskItem();
            jaTaskItem.setTitle(subFile.getName().substring(0,subFile.getName().length()-4));

            Encoder encoder = new Encoder();
            MultimediaInfo m = encoder.getInfo(subFile);
            System.out.println(count);
            jaTaskItem.setScore(Long.valueOf(m.getDuration()/60000).intValue());
            jaTaskItem.setUserid(1);
            jaTaskItem.setParentid(2);
            jaTaskItem.setStatus("0");
            jaTaskItem.setSeqNum(++count);
            System.out.println(jaTaskItemService.insertSelective(jaTaskItem));
        }
    }
}
